package com.hadoop.demo.mapreduce.lottery;

import com.hadoop.demo.mapreduce.wordcount.CountMapper;
import com.hadoop.demo.mapreduce.wordcount.CountReduce;
import com.hadoop.demo.mapreduce.wordcount.WordCountRunner;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * =================================
 * <p>
 * Created by cjj on 2018/10/16.
 * <p>
 * 描述: 计算彩票各个位置号码出现的次数
 */

public class CountNumRunner {

    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

        Configuration conf = new Configuration();

        Job job = Job.getInstance(conf);

        //设置整个job所有类在那个jar包
        job.setJarByClass(CountNumRunner.class);

        job.setMapperClass(CountNumMapper.class);
        job.setReducerClass(CountNumReduce.class);

        //指定mapper的输出类型
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(LongWritable.class);

        //指定reduce的输出类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(LongWritable.class);

        //把路径改为本地路径即可在本地运行

        //指定原始数据存放在那
        //FileInputFormat.setInputPaths(job,new Path("/home/cjj/project/docker-common/hadoopdemo/logs/input/"));
        FileInputFormat.setInputPaths(job,new Path("D:\\temp\\logs\\"));


        //指定处理结果的输出数据存放路径
        String outputPath = "D:\\temp\\logs\\output\\";
        Path path = new Path(outputPath);
        FileSystem fileSystem = FileSystem.get(conf);
        if(fileSystem.isDirectory(path)){
            fileSystem.delete(path,true);
        }
        FileOutputFormat.setOutputPath(job,path);

        //将job提交给集群运行
        job.waitForCompletion(true);

    }


}
